﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace Purdue.Converters
{
    public class ValueToStringEqualsParameterToStringToBooleanConverter : IValueConverter
    {
        public object DefaultValue { get; set; }

        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null || parameter == null)
            {
                return parameter == value;
            }

            return Equals(value.ToString(), parameter.ToString());
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var boolValue = value as bool?;
            if (boolValue.HasValue && boolValue.Value)
                return parameter;

            return this.DefaultValue;
        }

        #endregion
    }
}
